package com.intellagric.controller.module.ift_channel;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.ChannelVo;
import com.intellagric.pojo.IftChannel;
import com.intellagric.service.iftmonitor.ift_channel.ChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/20
 * @DESC： 痛都管理
 */
@Controller
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    /**
     * 添加通道信息
     * @Param channel
     * @return ResponseMessage
     */
    @RequestMapping("/channel/add")
    @ResponseBody
    public ResponseMessage add(IftChannel channel) {
        //添加默认参数
        channel.setId(UUID.randomUUID().toString().replaceAll("-",""));
        channel.setCreateDate(new Date());
        channel.setUpdateDate(new Date());
        return channelService.addChannel(channel);
    }

    /**
     * 删除通道信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/channel/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return channelService.deleteChannel(id);
    }

    /**
     * 修改通道信息
     * @Param channel
     * @return ResponseMessage
     */
    @RequestMapping("/channel/edit")
    @ResponseBody
    public ResponseMessage edit(IftChannel channel) {
        channel.setCreateDate(null);
        channel.setUpdateDate(new Date());
        return channelService.editChannel(channel);
    }

    /**
     * 查询通道信息
     * @return IftChannel
     */
    @RequestMapping("/channel/{id}")
    @ResponseBody
    public IftChannel get(@PathVariable String id) {
        return channelService.getChannelById(id);
    }

    /**
     * 查询通道信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/channel/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return channelService.getChannelList();
    }

    /**
     * 多条件查询通道信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/channel/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(ChannelVo channelVo) {
        return channelService.getChannelListByVo(channelVo);
    }

    /**
     * 分页查询通道信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/channel/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return channelService.getChannelPage(page,limit);
    }
}
